﻿#-*- coding:utf-8 -*-
import tkinter.messagebox as box
import requests
import os

Cloud = "http://www.coits.top:1030/coits/dove/"

def cloud(path) :
    str(path)
    if path[0] == "/" :
        return (Cloud + path[1:])
    else :
        return (Cloud + path)

def Networking_detection():
    try:
        cloud_path = cloud("Hi.cot")
        r = requests.get(cloud_path)
        with open(".\\tmp\\Hi.cot", "wb") as code:
            code.write(r.content)
    except :
        return (False)
    return (True)

def Get_archived(cloud_path,name) :
    if Networking_detection() == True :
        cloud_path = cloud(cloud_path)
        r = requests.get(cloud_path)
        if name[0] == "#" :
            try :
                with open(".\\tmp\\" + name[1:], "wb") as code:
                    code.write(r.content)
            except :
                box.showerror(title = "下载错误 Download error",
                              message = "下载" + cloud_path + "文件时出错\nError downloading " + cloud_path + " file")
                return (False)
        else :
            try :
                with open(name, "wb") as code:
                    code.write(r.content)
            except :
                box.showerror(title="下载错误 Download error",
                              message="下载" + cloud_path + "文件时出错\nError downloading " + cloud_path + " file")
                return (False)
        return (True)
    else:
        box.showerror(title = "无法连接至服务器 Networking Error",
                      message = "请检查网络连接状况\nPlease check the network connection")
        return (False)

def Del_file(path = r'.\\tmp'):
    ls = os.listdir(path)
    for i in ls:
        c_path = os.path.join(path, i)
        if os.path.isdir(c_path):
            del_file(c_path)
        else:
            os.remove(c_path)

def line_control(way) :
    pass
    # 执行控制转化程序